﻿using MediatR;
using Yuekao.API.Read.Command;
using Yuekao.Domain.API;
using Yuekao.Domain.BaseReposi;
using Yuekao.Domain.Entitys;

namespace Yuekao.API.Read.CommandHandler
{
    public class GetSchedulingHandler : IRequestHandler<GetSchedulingCommand, APIPagging<Scheduling>>
    {
        private readonly IBaseRepository<Scheduling> schedRepo;

        public GetSchedulingHandler(IBaseRepository<Scheduling> schedRepo)
        {
            this.schedRepo = schedRepo;
        }
        /// <summary>
        /// 医生排班
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIPagging<Scheduling>> Handle(GetSchedulingCommand request, CancellationToken cancellationToken)
        {
            APIPagging<Scheduling> res=new APIPagging<Scheduling>();
            var sched = schedRepo.GetAll();
            res.Code = APIEnum.Success;
            res.PageData = sched.ToList();
            res.Data = res.PageData.FirstOrDefault(); // 设置Data属性为第一个元素或默认值
            return res;
        }
    }      
        
}
